<?php
/**
 * 轮播图模型
 */

namespace app\h5\model;

use app\common\lib\RespCode;
use custom\Err;
use PDOStatement;
use think\Collection;
use think\Db;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;
use think\Model;
use app\api\controller\Config;

class House extends Model
{


    /**
     * 经纪人信息
     * @param $agent_id
     * @param $company_id
     * @return bool
     */
    public function getAgentInfo($agent_id)
    {
        $agent_info = db('company_agent')->where("id={$agent_id}  and deleted=0")->find();
        if (!$agent_info) {
            Err::add('数据不存在',RespCode::PARAMS_ERR);
            return false;
        }
        $data['name'] = $agent_info['name'];
        $data['cover'] = $agent_info['cover']?$agent_info['cover']:config('global.default_avt');
        $data['phone'] = $agent_info['phone'];
        $data['wechat_code'] = $agent_info['wechat_code'];
        return $data;

    }

    /**
     * 经纪人推荐房源显示
     * @param int $agent_id
     * @param int $house_id
     * @param array $data
     * @return array|bool
     */
    public function getAgentHouseDesc($agent_id=0,$house_id=0,$data=[]){
        if (!$data){
            return false;
        }
        //跟进房源id查询当前经纪人的推荐房源
        $data['agent_house_desc']='';
        $info=db('recommend_house')->where("agent_id={$agent_id} and house_id={$house_id}")->find();
        if ($info){
            $data['agent_house_desc']=$info['desc'];
            $data['title']=$info['name'];
        }
        return $data;
    }

}
